package com.fengdi.book.hard;

import java.util.Arrays;

public class MathProblems {
    public static class LargestNumber {
        public String largestNumber(int[] nums) {
            String[] ss = new String[nums.length];
            for(int i = 0; i < nums.length; i++) {
                ss[i] = String.valueOf(nums[i]);
            }
            Arrays.sort(ss, (a, b) -> {
                return (b + a).compareTo(a + b);
            });
            StringBuilder sb = new StringBuilder();
            for(String s : ss) {
                sb.append(s);
            }
            String res = sb.toString();
            return res.charAt(0) == '0' ? "0" : res;
        }
    }

    public static class MaxPoints {
        public int maxPoints(int[][] points) {
            if(points.length <= 2) return points.length;

            //TODO 先确定下来两个点，在确定第三个点是否在同一直线上
            int len = points.length;
            int res = 1;
            for(int i = 0; i < len; i++) {
                int[] x = points[i];
                for(int j = i + 1; j < len; j++) {
                    int[] y = points[j];
                    int cur = 2;
                    for(int k = j + 1; k < len; k++) {
                        int[] z = points[k];
                        int sl1 = (y[1] - x[1]) * (z[0] - y[0]);
                        int sl2 = (z[1] - y[1]) * (y[0] - x[0]);
                        if(sl1 == sl2) {
                            cur++;
                        }
                    }
                    res = Math.max(res, cur);
                }
            }
            return res;
        }
    }
}
